/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.explorer;

import org.json.JSONObject;
import org.webos.java.base.fs.FileDescriptor;
import org.webos.java.base.tree.TreeController;
import org.webos.java.base.tree.TreeControllerItem;
import org.webos.java.root.Log;

/**
 *
 * @author Kostya
 */
public class FileTreeItem extends TreeControllerItem<FileDescriptor, FileTreeItem>{

    public FileTreeItem(TreeController aController, FileDescriptor aDescriptor) {
        super(aController, aDescriptor);
        setId(aDescriptor.getId());
        setType(TYPE_UNKNOWN);
        if(!aDescriptor.isChildrenAllowed())
            setType(TYPE_LEAF);
    }

    @Override
    public void objectTOJSON(JSONObject aObject) {
        try {
            aObject.put("name", getObject().getName());
            aObject.put("icon_cls", getObject().getIcon());
        } catch (Throwable t) {
            Log.error(this, "Exception thrown: " + t.getMessage());
            t.printStackTrace();
        }
    }

}
